﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using LIM.forms.uc_CRM_KhachHang_ChiTiet;
using LIM.controller;
using LIM.model;

namespace LIM.forms
{
    public partial class radForm_CRM_KhachHang_ChiTiet : Telerik.WinControls.UI.RadForm
    {
        public radForm_CRM_KhachHang_ChiTiet()
        {
            InitializeComponent();            
        }
        public int IDKhachHang = 0;
        public delegate void RadPageViewSelectedPageChanged();
        public event RadPageViewSelectedPageChanged OnPageChange;
        public tbl_CRM_KhachHang SelectedEntity { set; get; }
        public DanhMucKhachHangController KhachHangController;

        private void radForm_CRM_KhachHang_ChiTiet_Load(object sender, EventArgs e)
        {
            uc_CRM_ThongTinKhachHang uc_CRM_ThongTinKhachHang = new uc_CRM_ThongTinKhachHang();
            uc_CRM_ThongTinKhachHang.Dock = DockStyle.Fill;
            this.radPageViewPage_ThongTinCoBan.Controls.Add(uc_CRM_ThongTinKhachHang);

            uc_CRM_DanhSachLienHe uc_CRM_ThongTinLienHe = new uc_CRM_DanhSachLienHe();
            uc_CRM_ThongTinLienHe.Dock = DockStyle.Fill;
            this.radPageViewPage_DanhSachLienHe.Controls.Add(uc_CRM_ThongTinLienHe);

            uc_CRM_KhachHang_ChiTiet_CongViec uc_CRM_KhachHang_ChiTiet_CongViec = new uc_CRM_KhachHang_ChiTiet_CongViec();
            uc_CRM_KhachHang_ChiTiet_CongViec.Dock = DockStyle.Fill;
            this.radPageViewPage_CongViec.Controls.Add(uc_CRM_KhachHang_ChiTiet_CongViec);

            uc_CRM_KhachHang_ChiTiet_BaoGia uc_CRM_KhachHang_ChiTiet_BaoGia = new uc_CRM_KhachHang_ChiTiet_BaoGia();
            uc_CRM_KhachHang_ChiTiet_BaoGia.Dock = DockStyle.Fill;
            this.radPageViewPage_BaoGia.Controls.Add(uc_CRM_KhachHang_ChiTiet_BaoGia);

            uc_CRM_KhachHang_ChiTiet_HopDong uc_CRM_KhachHang_ChiTiet_HopDong = new uc_CRM_KhachHang_ChiTiet_HopDong();
            uc_CRM_KhachHang_ChiTiet_HopDong.Dock = DockStyle.Fill;
            this.radPageViewPage_HopDong.Controls.Add(uc_CRM_KhachHang_ChiTiet_HopDong);

            uc_CRM_KhachHang_ChiTiet_ChiTieu uc_CRM_KhachHang_ChiTiet_ChiTieu = new uc_CRM_KhachHang_ChiTiet_ChiTieu();
            uc_CRM_KhachHang_ChiTiet_ChiTieu.Dock = DockStyle.Fill;
            this.radPageViewPage_ChiTieuDaKiemNghiem.Controls.Add(uc_CRM_KhachHang_ChiTiet_ChiTieu);

            uc_CRM_KhachHang_ChiTiet_CongNo uc_CRM_KhachHang_ChiTiet_CongNo = new uc_CRM_KhachHang_ChiTiet_CongNo();
            uc_CRM_KhachHang_ChiTiet_CongNo.Dock = DockStyle.Fill;
            this.radPageViewPage_CongNo.Controls.Add(uc_CRM_KhachHang_ChiTiet_CongNo);

            uc_CRM_KhachHang_ChiTiet_SanPhamNhaCungCap uc_CRM_KhachHang_ChiTiet_SanPhamNhaCungCap = new uc_CRM_KhachHang_ChiTiet_SanPhamNhaCungCap();
            uc_CRM_KhachHang_ChiTiet_SanPhamNhaCungCap.Dock = DockStyle.Fill;
            this.radPageViewPage_SanPhamNhaCungCap.Controls.Add(uc_CRM_KhachHang_ChiTiet_SanPhamNhaCungCap);

            uc_CRM_KhachHang_ChiTiet_ChiTieuNhaThauPhu uc_CRM_KhachHang_ChiTiet_ChiTieuNhaThauPhu = new uc_CRM_KhachHang_ChiTiet_ChiTieuNhaThauPhu();
            uc_CRM_KhachHang_ChiTiet_ChiTieuNhaThauPhu.Dock = DockStyle.Fill;
            this.radPageViewPage_ChiTieuNhaThauPhu.Controls.Add(uc_CRM_KhachHang_ChiTiet_ChiTieuNhaThauPhu);

            uc_CRM_KhachHang_ChiTiet_NhatKyLienLac uc_CRM_KhachHang_ChiTiet_NhatKyLienLac = new uc_CRM_KhachHang_ChiTiet_NhatKyLienLac();
            uc_CRM_KhachHang_ChiTiet_NhatKyLienLac.Dock = DockStyle.Fill;
            this.radPageViewPage_NhatKyLienLac.Controls.Add(uc_CRM_KhachHang_ChiTiet_NhatKyLienLac);

            this.radPageView_ThongTinKhachHang.SelectedPage = this.radPageViewPage_ThongTinCoBan;
            SelectedEntity = KhachHangController.LoadByID(IDKhachHang);
            if (OnPageChange != null)
                OnPageChange();

           // HideUnhidePageView_LoaiKhachHang(-1);
        }

        public void HideUnhidePageView_LoaiKhachHang(int index)
        {            
            if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_CongViec) > -1)
                this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_CongViec);
            if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_BaoGia) > -1) 
                this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_BaoGia);
            if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_HopDong) > -1) 
                this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_HopDong);
            if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_ChiTieuDaKiemNghiem) > -1) 
                this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_ChiTieuDaKiemNghiem);
            if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_CongNo) > -1) 
                this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_CongNo);
            if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_SanPhamNhaCungCap) > -1) 
                this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_SanPhamNhaCungCap);
            if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_ChiTieuNhaThauPhu) > -1) 
                this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_ChiTieuNhaThauPhu);
            if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_NhatKyLienLac) > -1) 
                this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_NhatKyLienLac);
            
            switch (index)
            {
                case 0:
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_CongViec);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_BaoGia);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_HopDong);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_ChiTieuDaKiemNghiem);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_CongNo);
                    //this.radPageView1.Pages.Add(radPageViewPage_SanPhamNhaCungCap);
                    //this.radPageView1.Pages.Add(radPageViewPage_ChiTieuNhaThauPhu);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_NhatKyLienLac);

                    break;
                case 1:
                    //this.radPageView1.Pages.Add(radPageViewPage_CongViec);
                    //this.radPageView1.Pages.Add(radPageViewPage_BaoGia);
                    //this.radPageView1.Pages.Add(radPageViewPage_HopDong);
                    //this.radPageView1.Pages.Add(radPageViewPage_ChiTieuDaKiemNghiem);
                    //this.radPageView1.Pages.Add(radPageViewPage_CongNo);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_SanPhamNhaCungCap);
                    //this.radPageView1.Pages.Add(radPageViewPage_ChiTieuNhaThauPhu);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_NhatKyLienLac);

                    break;
                case 2:
                    //this.radPageView1.Pages.Add(radPageViewPage_CongViec);
                    //this.radPageView1.Pages.Add(radPageViewPage_BaoGia);
                    //this.radPageView1.Pages.Add(radPageViewPage_HopDong);
                    //this.radPageView1.Pages.Add(radPageViewPage_ChiTieuDaKiemNghiem);
                    //this.radPageView1.Pages.Add(radPageViewPage_CongNo);
                    //this.radPageView1.Pages.Add(radPageViewPage_SanPhamNhaCungCap);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_ChiTieuNhaThauPhu);
                    this.radPageView_ThongTinKhachHang.Pages.Add(radPageViewPage_NhatKyLienLac);

                    break;
                default:
                    if (this.radPageView_ThongTinKhachHang.Pages.IndexOf(radPageViewPage_DanhSachLienHe) > -1)
                        this.radPageView_ThongTinKhachHang.Pages.Remove(radPageViewPage_DanhSachLienHe);
                    
                    break;
            }
        }

        private void radPageView_ThongTinKhachHang_SelectedPageChanged(object sender, EventArgs e)
        {
                SelectedEntity = KhachHangController.LoadByID(IDKhachHang);
                if (OnPageChange != null)
                    OnPageChange();
        }

        private void radPageView_ThongTinKhachHang_DoubleClick(object sender, EventArgs e)
        {

        }

        private void radPageView_ThongTinKhachHang_Click(object sender, EventArgs e)
        {

        }
    }
}
